/**
 * Created by chengcong on 2017/11/11.
 */
    var msg=window.sessionStorage['user_msg'];
//  if(!msg){
//		window.location = "../pages_doctor/html/login.html";
//	}
    msg=JSON.parse(msg);
$(function(){
    if(window.sessionStorage['changetime']=='false'){
        $('.zzzz').show();
        $('.mis-btn').hide();
    }else{
        $('.zzzz').hide();

    }    
    console.log(msg);
    $('.closemsg').on('click',function () {
        $('#msgnew').css('bottom','-200px');
    })

    $('.sticky-left-side').css('height',window.innerHeight-100+'px');
    //修改密码
    $('.change_Password').on('click', function(){
        $('.zzzz').show();
        $('.mis-btn').show();
    });
    $('.mis-btn').on('click',function () {
        $('.zzzz').hide();
    })
    $('.oldpwd').on('blur',function () {
        if($('.oldpwd').val()==''){
            $('.errmsg').text('原始密码不能为空');
            $('.errmsg').show();
        }else{
            $('.errmsg').hide();
        }
    });
    $('.newpwd').on('blur',function () {
        if($('.newpwd').val()==''){
            $('.errmsg').text('新密码不能为空');
            $('.errmsg').show();
        }else if($('.newpwd').val().length<6){
            $('.errmsg').text('密码少于6位');
            $('.errmsg').show();
        }else if($('.newpwd').val()!=$('.repeatpwd').val()){
            $('.errmsg').show();
            $('.errmsg').text('两次输入不一致');
        }else{
            $('.errmsg').hide();
        }
    });
    $('.repeatpwd').on('blur',function () {
        if($('.newpwd').val()!=$('.repeatpwd').val()){
            $('.errmsg').show();
            $('.errmsg').text('两次输入不一致');
        }else{
            $('.errmsg').hide();
        }
    });
   
    //角色
    if(msg.userrole==1){
        $('.doctor').addClass('active');
        $('.usermsg').text(msg.username+'医生');
        $('.doctor').siblings('li').not('.login-left').remove();
    }else if(msg.userrole==6){
        $('.custom-nav').html('');
        $('.custom-nav').html('<li class="menu-list doctor">' +
            '<a href="#"><i class="fa fa-home"></i> <span>助理</span></a>' +
            '<ul class="sub-menu-list">' +
            '<li><a href="javascript:void(0)" name="../pages_doctor/html/invitelist" title="邀请列表" class="iframeurl">邀请列表<span class="invitelist">0</span></a></li>' +
            '<li><a href="javascript:void(0)" name="../pages_doctor/html/unfinish" title="待办事项" class="iframeurl">待办事项<span class="unfinish">0</span></a></li>' +
            '<li><a href="javascript:void(0)" name="../pages_doctor/html/finish" title="已办事项" class="iframeurl">已办事项</a></li></ul></li>' +
            '<li class="login-left"><a href="../pages_doctor/html/login.html"><i class="fa fa-sign-in"></i> <span>登出</span></a></li>');
        $('.doctor').addClass('active');
        $('.usermsg').text(msg.username+'助理');
        $('.doctor').siblings('li').not('.login-left').remove();
    }else if(msg.userrole==3){

    }else if(msg.userrole==4){
        $('.apothecary').addClass('active');
        $('.usermsg').text(msg.username+'药师');
        $('.apothecary').siblings('li').not('.login-left').remove();
        $('#iframe').attr('src','../pages_apothecary/html/unfinish.html');
    }
    var cid = $('#nav_list> li>.submenu');
    cid.each(function(i){
        $(this).attr('id',"Sort_link_"+i);

    });
    console.log(window.innerHeight);
    $('#iframe').css('height',window.innerHeight-200+'px');
    $.ajax({
        url:url+'/server/assDocPending',
        type:'post',
        data:{
            id: msg.userid,
            userRole: msg.userrole
        },
         headers: {
          'Authorization': 'Bearer ' + msg.token
          },
        success:function (data) {
            console.log(data);
            if(data.code==200){
                $('.unfinish').text(data.data.length)
                if(data.data.length>0){
                    $('.unfinish').css('display','inline-block')
                }else{
                    $('.unfinish').css('display','none')
                }
            }
        }
    });
})
jQuery(document).ready(function(){
    $(document).on('click','.iframeurl',function(){
        var cid = $(this).attr("name")+'.html';
        var cname = $(this).attr("title");
        $("#iframe").attr("src",cid).ready();
        $("#Bcrumbs").attr("href",cid).ready();
        $(".Current_page a").attr('href',cid).ready();
        $(".Current_page").attr('name',cid);
        $(".Current_page").html(cname).css({"color":"#333333","cursor":"default"}).ready();
        $("#parentIframe").html('<span class="parentIframe iframeurl"> </span>').css("display","none").ready();
        $("#parentIfour").html(''). css("display","none").ready();
    });



});
/******/
$(document).on('click','.link_cz > li',function(){
    $('.link_cz > li').removeClass('active');
    $(this).addClass('active');
});
 function change_Password(){
        if($('.newpwd').val()==''||$('.oldpwd').val()==''){
            $('.errmsg').show();
            $('.errmsg').text('原始密码或新密码不能为空');
        }else
        if($('.newpwd').val().length<6){
            $('.errmsg').show();
            $('.errmsg').text('密码少于6位');
        }else if($('.newpwd').val()!=$('.repeatpwd').val()){
            $('.errmsg').show();
            $('.errmsg').text('两次输入不一致');
        }else{
            $.ajax({
                url:url+'/regist/changePassWord',
                type:'post',
                data:{
                    userPassword: $('.oldpwd').val(),
                    newUserPassword: $('.newpwd').val()
                },
                headers: {
                    'Authorization': 'Bearer ' + msg.token
                },
                success:function (d) {
                    console.log(d);
                    if(parseInt(d)==200){
                        alert('修改成功！');
                        window.sessionStorage.setItem("changetime", true);
                        $('.oldpwd').val('');
                        $('.repeatpwd').val('');
                        $('.newpwd').val('');
                        $('.zzzz').hide();
                        window.location = "../pages_doctor/html/login.html";
                    }else if(parseInt(d)==201){
                        $('.errmsg').show();
                        $('.errmsg').text('原始密码或新密码不能为空');
                    }else if(parseInt(d)==202){
                        $('.errmsg').show();
                        $('.errmsg').text('原始密码错误');
                    }else{
                        $('.errmsg').show();
                        $('.errmsg').text('发生意外错误，刷新后重试');

                    }
                }
            });
        }
    };
   
  //Enter修改密码
function onKeyPresss(event) {
	console.log(event)
	event = event || window.event;
	if(event.keyCode == 13) {
		change_Password();
	}
}
   

